package ca.seia.comp6521.a2.hashstorage;

import java.util.Arrays;

public class HashBucket {

	private HashStrategy hashStrategy;
	private int bucketCount;
	private int[] buckets;
	
	public HashBucket(HashStrategy hashStrategy, int bucketCount) {
		this.hashStrategy = hashStrategy;
		this.bucketCount = bucketCount;
		this.buckets = new int[bucketCount];
	}
	
	public void addCountToBucket(int item1,int item2) {
		this.buckets[getHashBucketIndex(item1, item2)]++;
	}
	
	public int getHashBucketIndex(int item1, int item2) {
		return (hashStrategy.getHashBucket(item1, item2) % bucketCount);
	}
	
	public int getHashBucketCount(int item1, int item2) {
		return 	this.buckets[getHashBucketIndex(item1, item2)];
	}
	
	public HashBitVector generateBitVector(int support) {
		boolean[] bitVector = new boolean[bucketCount];
		for(int index = 0 ; index < this.bucketCount ; index++) {
			if(this.buckets[index] >= support) {
				bitVector[index] = true;
			}
		}
		return new HashBitVector(bitVector, hashStrategy.get());
	}

	@Override
	public String toString() {
		return "HashBucket [bucketCount=" + bucketCount + ", buckets=" + Arrays.toString(buckets) + "]";
	}
	
}
